package com.spzx.product.controller;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.core.web.page.TableSupport;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.common.security.annotation.RequiresLogin;
import com.spzx.common.security.annotation.RequiresPermissions;
import com.spzx.common.security.annotation.RequiresRoles;
import com.spzx.product.domain.Brand;
import com.spzx.product.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
@Tag(name="品牌管理模块")
public class BrandContrller extends BaseController {

    @Resource
    BrandService brandService;

    @InnerAuth
    @Operation(summary = "获取所有品牌")
    @GetMapping("getBrandAllList")
    public R<List<Brand>> getBrandAllList() {

        return  R.ok(brandService.selectBrandAll());
    }



    @Operation(summary = "分页查询品牌")
    @GetMapping("list")
    public TableDataInfo list(Brand brand) {
        startPage();
        List<Brand> brands = brandService.selectBrandlist(brand);
        return  getDataTable(brands);
    }
    @Operation(summary = "查询所有品牌")
    @GetMapping
    public AjaxResult listAllBrand() {
        startPage();
        List<Brand> brands = brandService.selectBrandlist(null);
        return success(brands);
    }

    @Operation(summary = "根据三级id查询品牌列表")
    @GetMapping("/c3Id/{c3Id}")
    public AjaxResult listAllBrandC3Id(@PathVariable("c3Id") Long c3Id) {
        List<Brand> brands = brandService.selectBrandListC3Id(c3Id);
        return success(brands);
    }

    @Operation(summary = "根据品牌id查询品牌详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id")Long id) {
        return  success(brandService.selectBrandById(id));
    }

    @Operation(summary = "新增品牌")
    @RequiresPermissions("product:brand:add")
    @PostMapping
    public AjaxResult add(@RequestBody Brand brand){
        return success(brandService.insertBrand(brand));
    }

    @Operation(summary = "修改品牌信息")
    @RequiresRoles("admin")
    @PutMapping
    public AjaxResult update(@RequestBody Brand brand){

        return success(brandService.updateBrandById(brand));
    }



    //根据参数 判断单个删除还是批量删除
    @Operation(summary = "删除品牌信息")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") List<Long> ids){
        return success(brandService.removeBrandByid(ids));
    }



}
